package com.yang.lesson05;

import javafx.scene.control.RadioButton;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class JButtonDemo02 extends JFrame {
    public JButtonDemo02() {
        Container container = this.getContentPane();

        //将图片变为图标
        URL resource = JButtonDemo02.class.getResource("tc.jpg");
        ImageIcon icon = new ImageIcon(resource);

        //单选框
        JRadioButton button1 = new JRadioButton("1");
        JRadioButton button2 = new JRadioButton("2");
        JRadioButton button3 = new JRadioButton("3");

        //由于单选框只能选一个，需要分组，一组中只能选择一个
        ButtonGroup group = new ButtonGroup();
        group.add(button1);
        group.add(button2);
        group.add(button3);

        container.add(button1,BorderLayout.NORTH);
        container.add(button2,BorderLayout.CENTER);
        container.add(button3,BorderLayout.SOUTH);

        this.setVisible(true);
        this.setSize(500,300);
        this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);

    }

    public static void main(String[] args) {
        new JButtonDemo02();
    }

}
